package edu.gatech.cs2340.spring2012.team38;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * This class is used to search for a particular user account in the database
 * There must be an established connection to the database to use this class
 * @author Team 38
 */
public class Search 
{
	private SQLiteDatabase database;
	
	/**
	 * Creates a search object 
	 * @param db a database object 
	 */
	public Search(SQLiteDatabase db)
	{
		database = db;
	}

	/**
	 * Search for a particular user in the database based on username and password
	 * There is no duplicate user in the database so result should always be 0 or 1
	 * @param uname the username of the user account
	 * @param passw the password of the user account
	 * @return 0 for non existing user or 1 for existing user
	 */
	int searchForUser(String uname, String passw)
	{
		String searchUser = "SELECT * FROM User WHERE Username = \'" + uname + "\' AND Password = \'" + passw + "\'"; 
		Cursor resultCur = database.rawQuery(searchUser, null);
		if(resultCur.getCount() > 0)
		{
			return 1;
		}
		return 0;
	}
	
}
